package com.ruoyi.web.controller.order;

import com.ruoyi.order.domain.OrderRefund;
import com.ruoyi.order.service.IOrderRefundService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单退款记录Controller
 *
 * @author HHAOYU
 * @date 2020-12-18
 */
@RestController
@RequestMapping("/order/orderRefund")
public class OrderRefundController extends BaseController
{
    @Autowired
    private IOrderRefundService orderRefundService;

    /**
     * 查询订单退款记录列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderRefund:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderRefund orderRefund)
    {
        startPage();
        List<OrderRefund> list = orderRefundService.selectOrderRefundList(orderRefund);
        return getDataTable(list);
    }

    /**
     * 导出订单退款记录列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderRefund:export')")
    @Log(title = "订单退款记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderRefund orderRefund)
    {
        List<OrderRefund> list = orderRefundService.selectOrderRefundList(orderRefund);
        ExcelUtil<OrderRefund> util = new ExcelUtil<OrderRefund>(OrderRefund.class);
        return util.exportExcel(list, "orderRefund");
    }

    /**
     * 获取订单退款记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderRefund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderRefundService.selectOrderRefundById(id));
    }

    /**
     * 新增订单退款记录
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderRefund:add')")
    @Log(title = "订单退款记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderRefund orderRefund)
    {
        return toAjax(orderRefundService.insertOrderRefund(orderRefund));
    }

    /**
     * 修改订单退款记录
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderRefund:edit')")
    @Log(title = "订单退款记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderRefund orderRefund)
    {
        return toAjax(orderRefundService.updateOrderRefund(orderRefund));
    }

    /**
     * 删除订单退款记录
     */
    @PreAuthorize("@ss.hasPermi('cinema:orderRefund:remove')")
    @Log(title = "订单退款记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderRefundService.deleteOrderRefundByIds(ids));
    }
}
